var User = function () {
};
var ERROR_OK = 'S002';

function hasVip() {
    $.ajax({
        type: "get",
        url: ur + "rest/appUserController/info",
        async: false,
        headers: {
            'X-token': localStorage.token
        },
        dataType: 'json',
        success: function (data) {
            if (data.meta.code === ERROR_OK) {
                if (data.data.vipEndTime == null || data.data.vipEndTime < new Date().getTime()) {
                    return false;
                } else {
                    return true;
                }
            } else {
//              mui.toast(data.meta.message);
                return null;
            }
        }
    });
}
User.prototype.def_hasVip = function() {
    var def = $.Deferred();
    var vip;
    $.ajax({
        type: "get",
        url: ur + "rest/appUserController/info",
        async: true,
        headers: {
            'X-token': localStorage.token
        },
        dataType: 'json',
        success: function (data) {
            if (data.meta.code === ERROR_OK) {
                if (data.data.vipEndTime == null || data.data.vipEndTime < new Date().getTime()) {
                    vip = false;
                } else {
                    vip = true;
                }
            } else {
//              mui.toast(data.meta.message);
                vip = null;
            }
            def.resolve(vip);
        }
    });
    return def.promise();
}
User.prototype.getMessage = function () {
    $.ajax({
        type: "get",
        url: ur + "rest/appUserController/info",
        async: true,
        headers: {
            'X-token': localStorage.token
        },
        dataType: 'json',
        success: function (data) {
            if (data.meta.code === ERROR_OK) {
                localStorage.personId = data.data.id;
                localStorage.personName = data.data.nickName;
                $('.mine-photo').css('background-image', 'url(' + ur + data.data.img + ')');
                $('#name').text(data.data.nickName);
                $('#name').val(data.data.nickName);
                if (data.data.vipEndTime === null || data.data.vipEndTime < new Date().getTime()) {
                    localStorage.thisUser ? $('#vip').attr('src', '../../images/vip-none.png') : $('#vip').attr('src', '../images/vip-none.png')
                } else {
                    localStorage.thisUser ? $('#vip').attr('src', '../../images/mine-vip.png') : $('#vip').attr('src', '../images/mine-vip.png')
                }
                localStorage.removeItem('thisUser');
            } else {
//              mui.toast(data.meta.message);
            }
        }
    });

}